package com.buba.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.buba.mapper.LgUserMapper;
import com.buba.pojo.Dept;
import com.buba.mapper.DeptMapper;
import com.buba.pojo.LgUser;
import com.buba.pojo.other.DeptChildren;
import com.buba.service.DeptService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.lang.NonNullApi;
import org.springframework.stereotype.Service;
import java.util.List;

/**
 * <p>
 * 部门表 服务实现类
 * </p>
 *
 * @author MrJia
 * @since 2020-10-27
 */
@Service
public class DeptServiceImpl extends ServiceImpl<DeptMapper, Dept> implements DeptService {

    @Autowired
    private DeptMapper deptMapper;
    @Autowired
    private LgUserMapper lgUserMapper;

    @Override
    public DeptChildren selectList(String id) {
        List<DeptChildren> deptChildren = deptMapper.selectDept(id, null);
        DeptChildren deptChildren1 = deptChildren.get(0);
        deptChildren1.setChildren(deptMapper.selectDept(null, deptChildren1.getLevel()));
        return deptChildren1;
    }

    @Override
    public Boolean insertDept(Dept dept) {
        try {
            deptMapper.insert(dept);
            return true;
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
    }

    @Override
    public List<LgUser> showUser(LgUser lgUser) {
        QueryWrapper<LgUser> lgUserQueryWrapper = new QueryWrapper<>();
        return lgUserMapper.selectList(lgUserQueryWrapper.lambda().eq(LgUser::getUserName, lgUser.getUserName()).eq(LgUser::getState, lgUser.getState()));
    }
}
